var app_Dire = angular.module('starter.directives', []);
    // 返回功能
    app_Dire.directive('goBack', function ($state, $ionicHistory) {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                element.bind('click', function () {
                    if (attrs.goBack !== '') {
                        $state.go(attrs.goBack);
                    } else {
                        $ionicHistory.goBack();
                    }
                })
            }
        }
    })
    // 跳转功能
    .directive('goTo', function ($state) {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                element.bind('click', function () {
                    if (attrs.goTo !== '') {
                        if (attrs.id !== undefined) {
                            $state.go(attrs.goTo, {id: attrs.id});
                        } else {
                            $state.go(attrs.goTo);
                        }
                    }
                })
            }
        }
    })
    // 隐藏tabs
    .directive('hideTabs', function ($rootScope) {
        // Use for sub page hide tabs.
        return {
            restrict: 'A',
            link: function (scope, elem, attrs) {
                scope.$on('$ionicView.beforeEnter', function (event) {
                    $rootScope.hideTabs = attrs.hideTabs;
                });
            }
        };
    })
    //  密码明文切换
    .directive('togglePassword', function () {
        return {
            restrict: 'A',
            link: function (scope, element) {
                element.bind('click', function () {
                    if (element.hasClass('active')) {
                        element.removeClass('active');
                        element.next().attr('type', 'password'); // password
                    } else {
                        element.addClass('active');
                        element.next().attr('type', 'text'); //  text
                    }
                });
            }
        }
    })
    //动态设置div的宽度；
    .directive('getWidth', function () {
        return {
            restrict: "A",
            scope: {
                "rowHeight": '='
            },
            link: function (scope, element) {

                scope.$watch("rowHeight", function (value) {
                    console.log(scope.rowHeight);
                    $(element).css('width', scope.rowHeight + "px");
                }, false);
            }
        }
    })
    ;
